
import { createStore } from 'vuex'
 
const store = createStore({
 
state : {
  draftsObj: {},
  username: '',
  lines:[],
  wordowner: '',
  drawowner: '',
  anotherlines:[],
  usernames: [],
  rooms:[],
  turnnum:0,
  room:{
    roomname: '',
    password: '',
    roomnum: '',
    usernames: [],
  },
  words:[],
  newWord:{
    wordname:'',
    wordscript:'',
    wordcontent:[],
    worduser:''
  },
  word:'',
  historywords:[],
  historydraws:[],
  history:''

},
 
getters : {
  getDraftsObj: state => state.draftsObj
 
},
 
mutations : {
  setDraftsObj(state, obj) {
    state.draftsObj = { ...obj };
  },
  updateUsernames(state,usernames){
    state.usernames = usernames|| []
  },
  updateUsername(state,username){
    state.username = username || ''
  },
  pushNewLine(state,newLine){
    state.lines.push(newLine)
  },
  drawNewLine(state,newLine){
    const line = state.lines[state.lines.length - 1]
    line.points = newLine.points
  },
  updateRoom(state,room){
    state.room = room
  },
  updateRooms(state,rooms){
    //console.log(rooms)
    state.rooms = rooms || []
    //const newRoom = state.rooms.find(room => room.roomname === state.room.roomname)
    //state.room = newRoom
  },
  sendRooms(state,rooms){
    state.rooms = rooms || []
  },
  updatePass(state,pass){
    state.pass = pass
    console.log(state.pass)
  },
  updateWords(state,word){
    state.words = word || []
  },
  updateword(state,word){
    state.word = word || []
  },
  updateLines(state,lines){
    state.anotherlines = lines || []
  },
  updateAnotherLines(state){
    state.lines = state.anotherlines || []
  },
  updatewordowner(state,owner){
    state.wordowner = owner || []
  },
  updatedrawowner(state,owner){
    state.drawowner = owner || []
  },
  updatehistory(state,user){
    state.historydraws = user.draws || []
    state.historywords = user.guessword || []
    console.log(store.state.historydraws)
    console.log(store.state.historywords)
  },
},
 
actions : {

}
})
export default store